Shutdown Handling

RTX64 Shutdown handling prepares real-time devices that are controlled by RTX64 for a sudden Windows death caused either by a Windows emergency Blue screen crash or by “normal” Windows shutdown initiated outside of RTSS. When it happens, RTX64 postpones Windows imminent death and switches to RTX64 Shutdown mode which allows RTSS applications to make emergency clean-up calls. During RTX64 Shutdown handling, the RTSS subsystem is still operational and fully functional; Win32 RTX64 threads are not. Only RTSS processes with handlers attached by an RtAttachShutdownhandler call will function during RTX64 Shutdown. We will name such processes the shutdown processes. There is no time restriction on RTX64 Shutdown duration, it can even be forever (but Windows will never perform its own shutdown then).

Shutdown processes behave differently than other processes in RTX64 Shutdown mode. Only these RTSS processes remain functional during Windows shutdown while all others are frozen. Every shutdown handler, attached by RtAttachShutdownhandler, performs in separate RTSS threads context, and will be active during RTX64 Shutdown only. During normal Windows and RTX64 operations, these RTSS shutdown threads are dormant. Only one shutdown handler can be attached to RTSS process. The second RtAttachShutdownhandler call for the same process will be ignored unless there was RtReleaseShutdownhandler call.

The shutdown thread starts by calling the shutdown handler attached by RtAttachShutdownhandler This handler has two arguments, first one defined by user in the RtAttachShutdownhandler call, and the second one provided by RTX64 to describe the reason for the current shutdown. The second argument helps the shutdown handler dynamically detect what is wrong with Windows.

The shutdown thread is not the only active RTSS shutdown processes thread during Windows shutdown. All other RTSS shutdown processes threads are also active and not restricted from usual RTSS real-time performance (where Windows help is not needed). However, depending on the type of Windows shutdown, they can be restricted from all or some non-real-time calls. Windows will be able to continue its shutdown only after all RTSS shutdown processes have finished. As soon as the last RTSS shutdown process exits, RTSS is stopped or unloaded, and Windows continues the shutdown process.

During RTX64 shutdown, the RTSS shutdown process can manipulate all existing threads with its shutdown thread — it can postpone or even change its priority (this is not wise), but it cannot create new RTSS threads and objects. To obtain the shutdown thread handle, it can call GetCurrentThread in the shutdown thread context. The only difference is that if the shutdown thread exits or is terminated (because of “return”, ExitThread or TerminateThread calls) – the whole shutdown process also exits (exactly the same effect as it was the main thread).

NOTE: If a call to KeBugCheck or KeBugCheckEx occurs at high IRQL, and a shutdown handler has RtPrintf or printf calls, a shutdown handler may become stuck at the point of print call. This is because the Windows core(s) are not able to service the print request from RTSS due to being at high IRQL.

Subsystem Shutdown

You can stop the RTSS Subsystem and associated components directly from the information panel on RTX64 Control Panel Home page. If you attempt to stop the Subsystem while RTSS processes or Windows processes linked to RTX64 are still running, a dialog appears with a list of the running processes. See Stopping the Subsystem While Processes are Running.

Windows Blue Screen Shutdown

All shutdown process threads are active, plus there is one extra-thread, the shutdown thread. RTX64 Timer works, and all threads can perform real-time calls. However, they cannot call any non-real-time functions, involved Windows services, because only RTSS subsystem is able to work while Windows is fatally damaged and going to die. The only exceptions are RtPrintf and printf calls, which in RTX64 Shutdown mode will print directly on Blue Screen, but the volume of the printouts is restricted by the Blue Screen size.

Before switching in the Shutdown mode, RTX64 resets the screen to the Text mode. This reset may be time consuming and may not even be a real-time call (for enough time, interrupts may be disabled during this reset) if RTSS works on the same processor.

Windows Normal Shutdown

All shutdown process threads are alive, plus there is one extra thread, the shutdown thread. RTX64 Timer works, and all threads can perform almost any call, not just real-time calls. Since the Windows GUI is no longer responsive at this stage, printf and RtPrintf will not function correctly. Therefore, you should avoid calling printf and RtPrintf in your shutdown handler routines. Also, at this stage, it is not recommended that you create new RTSS threads and objects, because Windows has already shut down several services.

Important Considerations

Below are important things to consider with Shutdown Handling in RTX64:

Related topics: